﻿using BLL;
using BLL.Access;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;

namespace Web.Pages.QuShui.DiXiaS._2.YongHuGL
{
    /// <summary>
    /// 深井类型修改
    /// </summary>
    public partial class ShenJingLX : BasePage
    {
        #region 属性
        /// <summary>
        /// 当前水量年
        /// </summary>
        public static string Year { get; set; }
        /// <summary>
        /// 当前水量月
        /// </summary>
        public static string Month { get; set; }
        #endregion

        #region 变量

        /// <summary>
        /// 数据访问操作类
        /// </summary>
        SpHelper _spHelper = new SpHelper();
        /// <summary>
        /// 操作日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();
        #endregion

        #region 事件
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                //绑定水量年月
                string year;
                string month;
                _spHelper.P_QSYH_SHENGJINGLX("水量年","水量月",out year,out month);
                Year = year;
                Month = month;
                //绑定深井类型
                WordsManager manger = new WordsManager();
                PageTools.BindComboBox(cmJingLei, manger.Instance.FindWordsDataTableWithMiddleAffixByBelongID(WordsStruct.BelongID.井类型, " "));
                deChangeDate.Text = DateTime.Now.ToString("yyyy/MM/dd");
                   
            }
        }

        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            CallbackResult cr = new CallbackResult(e.Parameter);
            string flag;
            string message;
            string wellType;//井类型
            string oldNo;//原井编号
            int selectWellType = Convert.ToInt32(this.cmJingLei.Value);//井类型下拉框值
            string no = this.txtNo.Value.ToString();
            string letterNo = this.txtLetterNo.Value.ToString();
            try
            {
                //step1 检查井编号
                _spHelper.P_QSYH_CHECKJINGNO(no, out message, out oldNo, out wellType, out flag);
                if (flag == "0")
                {
                    cr.IsAlertMsg = true;
                    cr.Msg = message;
                    e.Result = cr.ToString();
                    return;
                }
                //step2 检查来函号
                _spHelper.P_QSYH_JIANCHALLH(no, letterNo, out flag, out message);
                if (flag == "-1")
                {
                    cr.IsAlertMsg = true;
                    cr.Msg = message;
                    e.Result = cr.ToString();
                    return;
                }
                //step3 检查所选井类型是否与先前相同
                _spHelper.P_QSYH_JINGLEIX(no, out wellType);
                if (selectWellType.ToString() == wellType)
                {

                    cr.IsAlertMsg = true;
                    cr.Msg = "井类型没有修改！";
                    e.Result = cr.ToString();
                    return;
                }
                //step4 判断井类型是否合法
                if (selectWellType != 1 && selectWellType != 2 && selectWellType != 3 && selectWellType != 4)
                {
                    cr.IsAlertMsg = true;
                    cr.Msg = "没有该井类型！";
                    e.Result = cr.ToString();
                    return;
                }
                //step5 修改操作
                try
                {
                    _spHelper.P_QSYH_JINGLEIXXG(no, selectWellType.ToString(), Year + "年" + Month + "月", LoginInfo.CurrentUser.UserID.ToString(), letterNo);
                    cr.IsAlertMsg = true;
                    cr.Msg = "修改成功！";
                    e.Result = cr.ToString();
                    return;
                }
                catch (Exception ex)
                {
                    cr.IsAlertMsg = true;
                    cr.Msg = "系统繁忙,请稍后再试！";
                    e.Result = cr.ToString();
                    return;
                }
           
            }
            catch (Exception)
            {
                cr.IsAlertMsg = true;
                cr.Msg = "系统繁忙,请稍后再试！";
                e.Result = cr.ToString();
                return;
            }
            

        }
        #endregion 

        #region 方法
        #endregion




      
    }
}